package ttk.muxiuesd.assetsloader;

import com.badlogic.gdx.assets.AssetManager;

/**
 * 整个游戏项目的资源加载
 * */
public class AssetsLoader {
    private static AssetsLoader instance;
    private final AssetManager assetManager = new AssetManager();

    public static synchronized AssetsLoader getInstance() {
        if (instance == null) {
            instance = new AssetsLoader();
        }
        return instance;
    }

    //直接同步加载 简单但效率不高
    //TODO 实现异步加载功能
    public <T> T get(String fileName, Class<T> type) {
        if (!assetManager.isLoaded(fileName, type)) {
            assetManager.load(fileName, type);
            assetManager.finishLoading();
        }
        return assetManager.get(fileName, type);
    }

    public void dispose() {
        assetManager.dispose();
    }

}
